<Project Sdk="Microsoft.Build.NoTargets">
  <!-- This is a wrapper project for wasm debugger tests, to enable use of the library test infrastructure -->

  <PropertyGroup>
    <TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
    <IsPublishable>false</IsPublishable>
    <EnableCoverageSupport>false</EnableCoverageSupport>
    <EnableRunSettingsSupport>false</EnableRunSettingsSupport>
    <IsBrowserWasmProject>false</IsBrowserWasmProject>
    <SkipTestUtilitiesReference>true</SkipTestUtilitiesReference>
    <BundleXunitRunner>true</BundleXunitRunner>
    <TestFramework>xunit</TestFramework>
    <DebuggerHost Condition="'$(DebuggerHost)' == ''">chrome</DebuggerHost>

    <CoreBuildDependsOn />
    <BundleTestWasmAppDependsOn>BundleDebuggerTestsForHelix</BundleTestWasmAppDependsOn>
    <ExtractTestClassNamesForHelix Condition="'$(ContinuousIntegrationBuild)' == 'true' or '$(ArchiveTests)' == 'true'">true</ExtractTestClassNamesForHelix>
    <RuntimeConfiguration Condition="'$(RuntimeConfiguration)' == ''">$(Configuration)</RuntimeConfiguration>
    <HelixTargetsFile>wasm.helix.targets</HelixTargetsFile>
  </PropertyGroup>

  <PropertyGroup>
    <RunScriptInputName Condition="'$(OS)' != 'Windows_NT'">RunScriptTemplate.sh</RunScriptInputName>
    <RunScriptInputName Condition="'$(OS)' == 'Windows_NT'">RunScriptTemplate.cmd</RunScriptInputName>

    <RunScriptInputPath>$(MSBuildThisFileDirectory)data\$(RunScriptInputName)</RunScriptInputPath>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="../DebuggerTestSuite/DebuggerTestSuite.csproj"
                      ReferenceOutputAssembly="false"
                      Private="false"
                      GlobalPropertiesToRemove="TargetFramework;TargetFrameworks;Configuration;TargetOS;TargetArchitecture"
                      AdditionalProperties="
                          RuntimeConfiguration=$(RuntimeConfiguration);
                          ArchiveTests=$(ArchiveTests);
                          ArchiveDirForHelix=$(TargetDir);
                          TestArchiveTestsDir=$(TestArchiveTestsDir);
                          ExtractTestClassNamesForHelix=$(ExtractTestClassNamesForHelix);
                          DebuggerHost=$(DebuggerHost);
                          DotNetForTests=$([MSBuild]::NormalizePath($(DotNetRoot), $(DotNetTool)))" />
  </ItemGroup>

  <Target Name="UpdateRunScriptCommands" BeforeTargets="GenerateRunScript">
    <ItemGroup>
      <RunScriptCommands Condition="'$(OS)' != 'Windows_NT'" Include="export DEBUGGER_TEST_PATH=$PWD/debugger-test" />
      <RunScriptCommands Condition="'$(OS)' == 'Windows_NT'" Include="set DEBUGGER_TEST_PATH=%25cd%25/debugger-test" />

      <!-- See https://github.com/dotnet/runtime/issues/89409 and https://github.com/microsoft/vstest/issues/2952 -->
      <RunScriptCommands Condition="'$(OS)' != 'Windows_NT'" Include="export VSTEST_TESTHOST_SHUTDOWN_TIMEOUT=2000" />
      <RunScriptCommands Condition="'$(OS)' == 'Windows_NT'" Include="set VSTEST_TESTHOST_SHUTDOWN_TIMEOUT=2000" />
    </ItemGroup>

    <ItemGroup Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(DebuggerHost)' == 'chrome'">
      <RunScriptCommands Condition="'$(OS)' != 'Windows_NT'" Include="export BROWSER_PATH_FOR_TESTS=$HELIX_CORRELATION_PAYLOAD/chrome-linux/chrome" />
      <RunScriptCommands Condition="'$(OS)' == 'Windows_NT'" Include="set BROWSER_PATH_FOR_TESTS=%HELIX_CORRELATION_PAYLOAD%\chrome-win\chrome.exe" />
    </ItemGroup>

    <ItemGroup Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(DebuggerHost)' == 'firefox'">
      <RunScriptCommands Condition="'$(OS)' != 'Windows_NT'" Include="export BROWSER_PATH_FOR_TESTS=$HELIX_CORRELATION_PAYLOAD/firefox/firefox" />
    </ItemGroup>

    <ItemGroup Label="Don't log to console on CI" Condition="'$(ContinuousIntegrationBuild)' == 'true'">
      <RunScriptCommands Condition="'$(OS)' != 'Windows_NT'" Include="export SKIP_LOG_TO_CONSOLE=1" />
      <RunScriptCommands Condition="'$(OS)' == 'Windows_NT'" Include="set SKIP_LOG_TO_CONSOLE=1" />
    </ItemGroup>

    <PropertyGroup>
      <_DotnetCommand Condition="'$(OS)' != 'Windows_NT'">dotnet</_DotnetCommand>
      <_DotnetCommand Condition="'$(OS)' == 'Windows_NT'">dotnet.exe</_DotnetCommand>

      <RunScriptCommand>$(_DotnetCommand) test DebuggerTestSuite/DebuggerTestSuite.dll</RunScriptCommand>
      <RunScriptCommand>$(RunScriptCommand) /e:WasmEnableThreads=$(WasmEnableThreads)</RunScriptCommand>
      <RunScriptCommand>$(RunScriptCommand) &quot;-l:trx%3BLogFileName=testResults.trx&quot;</RunScriptCommand>
      <RunScriptCommand Condition="'$(ContinuousIntegrationBuild)' == 'true'">$(RunScriptCommand) &quot;-l:console%3BVerbosity=normal&quot;</RunScriptCommand>

      <RunScriptCommand Condition="'$(OS)' != 'Windows_NT'">$(RunScriptCommand) --results-directory &quot;$TEST_LOG_PATH&quot;</RunScriptCommand>
      <RunScriptCommand Condition="'$(OS)' == 'Windows_NT'">$(RunScriptCommand) --results-directory &quot;%TEST_LOG_PATH%&quot;</RunScriptCommand>

      <RunScriptCommand Condition="'$(OS)' != 'Windows_NT'">$(RunScriptCommand) %24TEST_ARGS</RunScriptCommand>
      <RunScriptCommand Condition="'$(OS)' == 'Windows_NT'">$(RunScriptCommand) %TEST_ARGS%</RunScriptCommand>

      <!--<RunScriptCommand Condition="'$(ContinuousIntegrationBuild)' == 'true' or '$(XUnitShowProgress)' == 'true'">$(RunScriptCommand) -v normal</RunScriptCommand>-->
      <RunScriptCommand>$(RunScriptCommand) -v diag</RunScriptCommand>
    </PropertyGroup>
  </Target>

  <Target Name="BundleDebuggerTestsForHelix" />
</Project>
